package com.iot.ic.service;



import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iot.ic.common.CustomException;
import com.iot.ic.common.ReturnCode;
import com.iot.ic.dao.IllegalInfoMapper;
import com.iot.ic.dao.RefereeInfoMapper;
import com.iot.ic.dao.TeamInfoMapper;
import com.iot.ic.model.IllegalInfo;
import com.iot.ic.model.MatchScenesInfo;
import com.iot.ic.model.RefereeInfo;
import com.iot.ic.model.TeamInfo;

/**
 * Created by xiuge on 2017/2/20.
 */
@Service
public class IllegalServiceImpl implements IllegalService {

	@Autowired
	private IllegalInfoMapper illegalInfoMapper;
	
	@Autowired
	private MatchScenesService matchScenesService;

	@Override
	public List<IllegalInfo> listIllegalInfosByScenes(Integer scenesId) {
		List<IllegalInfo> resultList = illegalInfoMapper.listIllegalInfosByScenes(scenesId);
		return resultList;
	}

	@Override
	public int deleteIllegalInfo(Integer illegalId) {
		IllegalInfo illegalInfo = illegalInfoMapper.selectByPrimaryKey(illegalId);
		int result = illegalInfoMapper.deleteIllegalInfo(illegalId);
		//修改场景违规数量
		if (result > 0) {
			MatchScenesInfo matchScenesInfo = matchScenesService.getMatchScenesById(illegalInfo.getScenesId());
			int oldIllegalCount = matchScenesInfo.getIllegalCount();
			matchScenesInfo.setIllegalCount(oldIllegalCount -1);
			result = matchScenesService.updateMatchScenes(matchScenesInfo);
		}
		return result;
	}

	@Override
	public int addIllegalInfo(IllegalInfo illegalInfo) {
		int result = illegalInfoMapper.insert(illegalInfo);
		//修改场景违规数量
		if (result > 0) {
			MatchScenesInfo matchScenesInfo = matchScenesService.getMatchScenesById(illegalInfo.getScenesId());
			int oldIllegalCount = matchScenesInfo.getIllegalCount();
			matchScenesInfo.setIllegalCount(oldIllegalCount + 1);
			result = matchScenesService.updateMatchScenes(matchScenesInfo);
		}
		return result;
	}

	@Override
	public IllegalInfo getIllegalInfoById(Integer illegalId) {
		IllegalInfo illegalInfo = illegalInfoMapper.selectByPrimaryKey(illegalId);
		return illegalInfo;
	}

	@Override
	public int updateIllegalInfo(IllegalInfo illegalInfo) {
		int result = illegalInfoMapper.updateByPrimaryKeySelective(illegalInfo);
		return result;
	}



	
	
	
	
	
	
}
